package com.yy.ant.chat.service.impl;

import com.yy.ant.chat.entity.Chatmessage;
import com.yy.ant.chat.mapper.ChatmessageMapper;
import com.yy.ant.chat.service.IChatmessageService;
import com.yy.model.ResultMsg;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 聊天记录表 服务实现类
 * </p>
 *
 * @author liyingying
 * @since 2020-01-06
 */
@Service
public class ChatmessageServiceImpl extends ServiceImpl<ChatmessageMapper, Chatmessage> implements IChatmessageService {
	
	@Autowired
	private ChatmessageMapper chatmessageMapper;
	//获取未读消息数量
	@Override
	public ResultMsg unreadMsgCount(String id,String uid,int type) {
		QueryWrapper<Chatmessage> queryWrapper=new QueryWrapper<>();
		queryWrapper.eq("froms", id).or().eq("toid", uid).eq("type", type).orderByDesc("timestamp");
		IPage<Chatmessage> listPage=chatmessageMapper.selectPage(new Page<>(Integer.valueOf(1),Integer.valueOf(500)),queryWrapper);
		List<Chatmessage> list=listPage.getRecords();
		ResultMsg resultMsg=new ResultMsg();
		resultMsg.setData(list);
		return resultMsg;
	}

}
